package sns.service;

import org.springframework.transaction.annotation.Transactional;
import sns.bean.Relation;
import sns.bean.User;
import sns.dao.RelationDao;

@Transactional
public class RelationService {

	private RelationDao relationDao;
	
	/**
	 * Get the relation object of which source and target are the same as parameters. 
	 * 
	 * @param source
	 * @param target
	 * @return
	 */
	public Relation getRelation(User source, User target){
		return relationDao.getRelation(source, target);
	}
	
	/**
	 * Check if user1 has followed user2.
	 * 
	 * @param user1
	 * @param user2
	 * @return
	 */
	public boolean checkIfFollow(User user1, User user2){
		return relationDao.checkIfFollow(user1, user2);
	}
	
	/**
	 * Get the number of followers(i.e. the number of fans)
	 * 
	 * @param user
	 * @return
	 */
	public int getFollowerNum(User user){
		return relationDao.getFollowerNum(user);
	}
	
	/**
	 * Get the number of followees(i.e. the number of idols)
	 * 
	 * @param user
	 * @return
	 */
	public int getFolloweeNum(User user){
		return relationDao.getFolloweeNum(user);
	}

	public void setRelationDao(RelationDao relationDao) {
		this.relationDao = relationDao;
	}
}
